"use strict";
cc._RF.push(module, '02e42fAuDdJ9KYAMJCSMYZs', 'Utils');
// script/original/Standar/Utils/Utils.js

"use strict";

module.exports = {
  //获取地址栏的信息
  getrequest: function getrequest(signal) {
    function GetRequest(name) {
      var url = location.search; //获取url中"?"符后的字串

      var theRequest = new Object();

      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");

        for (var i = 0; i < strs.length; i++) {
          theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
      }

      return theRequest[name];
    }

    return GetRequest(signal);
  },
  getUrlParama: function getUrlParama() {
    //首先获取到当前页面的地址栏信息
    var url = window.location.href;
    var obj = {};
    var reg = /\?/;

    if (url.match(reg)) {
      //判断传入参数，以问号截取，问号后是参数
      var chars = url.split('?')[1]; //再截&号

      var arr = chars.split('&'); //获得截取后的数组为键值对字符串

      for (var i = 0; i < arr.length; i++) {
        //保守一点确定看是否为 name=value形式
        var num = arr[i].indexOf("=");

        if (num > 0) {
          //拼接字符串
          var name = arr[i].substring(0, num);
          var value = arr[i].substr(num + 1); //拼接对象，并转码

          obj[decodeURIComponent(name)] = decodeURIComponent(value);
        }
      }
    }

    return obj;
  },

  /**
  * 补齐0
  * @param num： 被操作数
  * @param n： 固定的总位数
  */
  prefixZero: function prefixZero(num, n) {
    return (Array(n).join(0) + num).slice(-n);
  },
  //随机整数
  random: function random(n, m) {
    var random = Math.floor(Math.random() * (m - n + 1) + n);
    return random;
  },
  //判断字符串为空
  isEmptyString: function isEmptyString(obj) {
    if (obj === null) return true;

    if (typeof obj === 'undefined') {
      return true;
    }

    if (typeof obj === 'string') {
      if (obj === "") {
        return true;
      }

      var reg = new RegExp("^([ ]+)|([　]+)$");
      return reg.test(obj);
    }

    return false;
  },
  //验证手机号码是否正确
  isPhoneNumberCorrect: function isPhoneNumberCorrect(phonenumber) {
    if (!/^1[34578]\d{9}$/.test(phonenumber)) {
      return false;
    }

    return true;
  },

  /**
   * 获取两个数之间的随机值
   * @param {int} min 最小值
   * @param {int} max 最大值
   */
  getRndInteger: function getRndInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
};

window.confirm = function (message) {
  var iframe = document.createElement("IFRAME");
  iframe.style.display = "none";
  iframe.setAttribute("src", 'data:text/plain,');
  document.documentElement.appendChild(iframe);
  var alertFrame = window.frames[0];
  var result = alertFrame.window.confirm(message);
  iframe.parentNode.removeChild(iframe);
  return result;
};

window.alert = function (name) {
  var iframe = document.createElement("IFRAME");
  iframe.style.display = "none";
  iframe.setAttribute("src", 'data:text/plain,');
  document.documentElement.appendChild(iframe);
  window.frames[0].window.alert(name);
  iframe.parentNode.removeChild(iframe);
};

cc._RF.pop();